<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:heigth="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>代理商设备情况查看</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px;">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>机器码：</th>
                    <td style="width:120px">
                        <input name="machineCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>业务码：</th>
                    <td style="width:120px">
                        <input name="businessCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>可用状态：</th>
                    <td style="width:120px">
                        <select id="statusSelect" name="status" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="0">全部</option>
                            <option value="1">启用</option>
                            <option value="2">禁用</option>
                        </select>
                    </td>
                    <th>绑定情况：</th>
                    <td style="width:120px">
                        <select id="bindStatusSelect" name="bindStatus" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="0">全部</option>
                            <option value="1">初始化</option>
                            <option value="2">已绑代理商</option>
                            <option value="3">已绑合作伙伴</option>
                        </select>
                    </td>
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"> </table>


<div id="showT" class="easyui-window" title="终端详情" data-options="closed:true,iconCls:'icon-save'" style="width:1500px;height:500px;padding:10px;">
    <table id="dgt" height="100%"> </table>
</div>

<div id="pop" class="pop" style="display:none">
    <div class="pop_head"><a href="javascript:void(0);" onclick="hide()">关闭</a></div>
    <div class="pop_body"><img id="img_a" src="" alt=""/></div>
</div>
<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        dg.datagrid({
            url:'/v1/api0/equipment/agentEquipmentSituationList',
            columns:[[
                {field:'id',hidden:true,title:'中控ID',width:100},
                {field:'machineCode',title:'机器码',width:100},
                {field:'businessCode',title:'业务码',width:100},
                {field:'agentId',title:'代理商id',width:100,hidden:"true"},
                {field:'agentName',title:'代理商',width:100},
                {field:'partnerId',title:'合作伙伴id',width:100,hidden:"true"},
                {field:'partnerName',title:'合作伙伴',width:100},
                {field:'terminalNum',title:'终端数量',width:100},
                {field:'qrCode',title:'二维码',width:100,formatter: function(value,row,index){
                        if(row.qrCode != null && row.qrCode != ""){
                            return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="show(\''+row.businessCode+'\')">查看</a>';
                        }
                    }},
                {field:'qrCodeUrl',title:'二维码请求地址',width:100},
                {field:'createTime',title:'创建时间',width:100,formatter: formatDateTime},
                {field:'status',title:'可用状态',width:40,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "启用";
                        case 2: return "禁用";
                    }
                }},
                 {field:'bindStatus',title:'绑定情况',width:40,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "初始化";
                        case 2: return "已绑代理商";
                        case 3: return "已绑合作伙伴";
                    }
                }},
                {field:'action',title:'操作',width:100,formatter: function(value,row,index){
                        return  '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showTerminal(\''+row.id+'\')">终端信息</a>';
                }}
            ]],
            title:'中控设备管理',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true,
            toolbar: [ {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }]
        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();

        $('#dg').datagrid({
            url:'/v1/api0/equipment/agentEquipmentSituationList',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        $('#bindStatusSelect').combobox('setValue', '0');
        onSearch();
    }

    //查看终端信息。
     function showTerminal(id) {
        var dgt = $('#dgt').datagrid();
        dgt.datagrid({
            url:'/v1/api0/equipment/showTerminal',
            queryParams:{consoleId:id},
            columns:[[
                 {field:'id',title:'ID',width:60,hidden:"true"},
                {field:'machineCode',title:'机器码',width:100},
                {field:'businessCode',title:'业务码',width:100},
                {field:'status',title:'状态',width:100},
                {field:'createime',title:'创建时间',width:100,formatter: formatDateTime},
                {field:'creater',title:'创建人',width:100},
                {field:'consoleId',title:'中控id',width:100,hidden:"true"},
                {field:'qrCode',title:'二维码',width:100,formatter: function(value,row,index){
                        if(row.qrCode != null && row.qrCode != ""){
                            return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="show(\''+row.businessCode+'\')">查看</a>';
                        }
                 }}]],
                pagination: true
                });
        $('#showT').window('open');
    }

var EX = {
        addEvent:function(k,v){
            var me = this;
            if (me.addEventListener)
                me.addEventListener(k, v, false);
            else if(me.attachEvent)
                me.attachEvent("on" + k, v);
            else
                me["on" + k] = v;
        },
        removeEvent:function(k,v){
            var me = this;
            if (me.removeEventListener)
                me.removeEventListener(k, v, false);
            else if (me.detachEvent)
                me.detachEvent("on" + k, v);
            else
                me["on" + k] = null;
        },
        stop:function(evt){
            evt = evt || window.event;
            evt.stopPropagation?evt.stopPropagation():evt.cancelBubble=true;
        }
    };
document.getElementById('pop').onclick = EX.stop;
    var url = '#';
    function show(imgname){
        var o = document.getElementById('pop');
        o.style.display = "";
        $("#img_a").attr("src",serverPath+'/GetImage?bt=staticInfoImage&fn='+imgname+'.png'+'&sd=qrcodeImage/');
        setTimeout(function(){EX.addEvent.call(document,'click',hide);});
    }
    function hide(){
        var o = document.getElementById('pop');
        o.style.display = "none";
        EX.removeEvent.call(document,'click',hide);
    }
</script>
</body>
</html>
